﻿//*****************************************************************************
//** Project:PAC4SL
//** Copyright 2011 PatternWell LLC
//** Revision History:
//** Version 1.0 - Initial Release
//*****************************************************************************

using System.Windows.Controls;

namespace PatternWell.PAC.SL
{
    /// <summary>
    /// Extension of the built in silverlight page control that includes logic for a PAC view.
    /// </summary>
    public partial class PageView:Page,IViewContract
    {
        #region IViewResource

        /// <summary>
        /// Helper method that is called by the hosting controller, that informs the view to initialize all contract resources.
        /// This method is implemented as virtual so you can provide additonal initialization logic.
        /// By default this will get called when the view is attached to the controller.
        /// </summary>
        public virtual void InitializeView()
        {
            InitializeContractResources();
        }

        /// <summary>
        /// Helper method that is called by the hosting controller, that informs the view to release all resources that are consumed by the controller, and to reinitilize all resources.
        /// This method is implementated as virtual so you can provide additional detach processing.
        /// </summary>
        public virtual void DetachViewResources()
        {
            DetachContract();
        }

        /// <summary>
        /// Helper method that informs the controller if the view is in a state where it can be released.
        /// By default it will return true. This method is implemented as a virtual method so it can be overridden.
        /// </summary>
        /// <returns>Information about the release status.</returns>
        public virtual ReleaseInfo CanReleaseResources()
        {
            return new ReleaseInfo { CanRelease = true };
        }

        /// <summary>
        /// Releases all resources that are subscribed to by the subscribing controller.
        /// </summary>
        public virtual void ReleaseResources()
        {
            ReleaseViewContract();
        }

        #endregion

        #region Implementation Helpers

        /// <summary>
        /// Patrial method that is implemented by the contract to initialize all contract resources.
        /// </summary>
        protected virtual void InitializeContractResources()
        {
            //Intentinally blank
        }

        /// <summary>
        /// Partial method that gets implemented by the contract to release all resources consumed by the hosting controller.
        /// </summary>
        protected virtual void ReleaseViewContract()
        {
            //Intentinally blank
        }

        /// <summary>
        /// Partial method that is implemented by the contract to detach resources from the hosting controller, and to reset the view model. 
        /// </summary>
        protected virtual void DetachContract()
        {
            //Intentinally blank
        }


        #endregion
    }
}
